package com.itany.cloud.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.itany.cloud.global.ExceptionUtil;
import com.itany.cloud.util.ResponseResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Author:shixiaojun@itany.com
 * Date:2022/8/11 15:47
 * Version:1.0-SNAPSHOT
 * Description:
 */
@RestController
public class HelloController {

    @SentinelResource(value = "f1",blockHandler = "handlerException")
    @RequestMapping("/f1")
    public ResponseResult f1(){
        return ResponseResult.success();
    }

    public ResponseResult handlerException(BlockException e){
        return ResponseResult.fail("Sentinel异常,异常为:"+e);
    }

    @SentinelResource(value = "f2",blockHandlerClass = ExceptionUtil.class,blockHandler = "handlerException")
    @RequestMapping("/f2")
    public ResponseResult f2(){
        return ResponseResult.success();
    }

}
